package com.northone.statistics.widget;

import com.northone.statistics.widget.DragLayout.Status;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.LinearLayout;

public class MyLinearLayout extends LinearLayout {

	private DragLayout dragLayout;

	public MyLinearLayout(Context context) {
		super(context);
	}

	public MyLinearLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public MyLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
	}
	
	@Override
	public boolean onInterceptTouchEvent(MotionEvent ev) {
		if (dragLayout != null && dragLayout.getStatus() != Status.Close) {
			// 不是关闭状态 , 直接拦截, 不往下传递了
			return true;
		}else {
			// 如果当前是关闭状态, 按原来的判断处理
			return super.onInterceptTouchEvent(ev);
		}
	}
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if (dragLayout != null && dragLayout.getStatus() != Status.Close) {
			if (event.getAction() == MotionEvent.ACTION_UP) {
				// 如果手指抬起, 执行关闭动画
				dragLayout.close();
			}
			return true;
		}else {
			return super.onTouchEvent(event);
		}
	}
	public void setDragLayout(DragLayout dl) {
		this.dragLayout = dl;
	}
}
